package yu.zhou.njupt.fileprocessor;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;

import yu.zhou.njupt.fileprocessor.bean.CaseSensitive;
import yu.zhou.njupt.fileprocessor.bean.MatchMode;

/**
 * @author yu.zhou
 * 
 */
@SuppressWarnings("unused")
public class FileList{
    
    private static final Logger logger = LoggerFactory.getLogger(FileList.class);
    private BufferedWriter br = null;
    
	public int work(File sourcePath, File outputFile) throws Exception {
		if (!sourcePath.exists()) {
			throw new Exception("源文件的根目录不存在,请检查!!!");
		} else if (!sourcePath.isDirectory()) {
			throw new Exception("提供的根目录是一个文件,请检查!!!");
		} else {
			br = new BufferedWriter(new FileWriter(outputFile));
			ListFiles(sourcePath);
			br.close();

			return 0;
		}
	}
	
	public int work(String sourcePathStr, String outputFileStr) throws Exception {
	    return work(new File(sourcePathStr), new File(outputFileStr));
	}
	
	private void ListFiles(File sourcePath) throws IOException {
	    String sourcePathStr = sourcePath.getAbsolutePath() + File.separator;
	    
		for (File file : sourcePath.listFiles()) {
			if (file.isDirectory()) {
			    ListFiles(file);
			} else {
				br.write(file.getAbsolutePath() + "\r\n");
			}
		}
	}
	
}
    
